package EVO;

import EVO.dao.StudentDao;
import EVO.entity.Student;
import EVO.service.StudentService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class MyTest01 {
    @Test
    public void test01(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        String[] name = ac.getBeanDefinitionNames();
        for(String s : name){
            System.out.println("容器中的类："+s+" | "+ac.getBean(s).getClass().getName());
        }
    }


    @Test
    public void testDaoInsert(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        StudentDao dao = (StudentDao) ac.getBean("studentDao");
        Student stu = new Student(8,"小红","xiaohong@163.com",18);
        int result = dao.insertStudent(stu);
        System.out.println("result=== "+result);
    }



    @Test
    public void testServiceInsert(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        StudentService studentService = (StudentService)ac.getBean("studentService");
        Student stu = new Student(9,"小花","xiaohua@163.com",22);
        int result = studentService.addStudent(stu);
        System.out.println("result=== "+result);
    }


    @Test
    public void testServiceSelect(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        StudentService studentService = (StudentService)ac.getBean("studentService");
        List<Student> stuList = studentService.queryStudent();
        for(Student stu : stuList){
            System.out.println(stu);
        }
    }
}
